﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace ZG_member
{
    public partial class UpdateAppointment : Form
    {
        appointment form;
        public UpdateAppointment(appointment form1)
        {
            form = form1;
            InitializeComponent();
        }

        private void UpdateAppointment_Load(object sender, EventArgs e)
        {
            this.timer1.Start();
        } 
        private void btn_Update_Click(object sender, EventArgs e)
        {
            ZG_member.Model.informationShare Model = new Model.informationShare();
            ZG_member.BLL.informationShare Up_appoint = new BLL.informationShare();
            if (textBox1.Text.Trim() != "")
            {
                int id = Convert.ToInt32(textBox1.Text.Trim());
                Model.name = this.txt_Name.Text.ToString();
                Model.contact = this.txt_Mobile.Text.ToString();
                Model.createDate=Convert.ToDateTime(this.dtp_check_day.Text+" "+this.dtp_check_time.Text);
                Model.appointmentDate=Convert.ToDateTime(this.dtp_appoint_day.Text+" "+this.dtp_appoint_time.Text);
                Model.appointmentWays=this.cmb_ways.SelectedItem.ToString();
                Model.status=this.cmb_Status.SelectedItem.ToString();
                Model.memo = this.txt_Memo.Text.ToString();
                if (Up_appoint.Update(id, Model) > 0)
                {
                    MessageBox.Show("修改成功");
                    getList("");
                    this.Close();
                }
                else
                {
                    MessageBox.Show("修改失败");
                }
            }
        }
        private void getList(string strWhere)
        {
            ZG_member.BLL.informationShare appoint_Bll = new BLL.informationShare();
            appointment ap = new appointment();
            form.dataGridView1.DataSource = appoint_Bll.getAppointList(strWhere).Tables[0];
        }
        private void timer1_Tick(object sender, EventArgs e)
        {
            this.Left += 2;
            this.Opacity += 0.1;
            if (this.Opacity == 1)
            {
                this.timer1.Stop();
            }
        }

        private void timer2_Tick(object sender, EventArgs e)
        {
            this.Top = this.Top + 10;
            this.Opacity = this.Opacity - 0.06;
            if (Opacity <= 0)
            {
                this.timer2.Stop();
                this.Close();
            }
        }

        private void btn_Close_Click(object sender, EventArgs e)
        {
            this.timer2.Start();
        }

        private void txt_Mobile_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (!(((e.KeyChar >= '0') && (e.KeyChar <= '9')) || e.KeyChar <= 31))
            {
                if (e.KeyChar == '.')
                {
                    if (((TextBox)sender).Text.Trim().IndexOf('.') > -1)
                        e.Handled = true;
                }
                else
                    e.Handled = true;
            }
            else
            {
                if (e.KeyChar <= 31)
                {
                    e.Handled = false;
                }
                else if (((TextBox)sender).Text.Trim().IndexOf('.') > -1)
                {
                    if (((TextBox)sender).Text.Trim().Substring(((TextBox)sender).Text.Trim().IndexOf('.') + 1).Length >= 4)
                        e.Handled = true;
                }
            }
        }

    }
}
